<template>
  <div class="follow">
      <hm-header>我的关注</hm-header>
      <div class="item" v-for="item in list" :key="item.id">
          <div class="left">
              <img :src="$axios.defaults.baseURL + item.head_img" alt="">

          </div>
          <div class="center">
              <p class="name">{{ item.nickname }}</p>
              <p class="time">{{ item.create_data | time }}</p>
          </div>
          <div class="right" @click="cancelFollow(item.id)">取消关注</div>

      </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      list: []
    }
  },
  created () {
    // this.follow(1)
    // this.follow(2)
    // this.follow(3)
    // this.follow(4)
    // this.follow(5)
    this.getFollowList()
  },
  methods: {
    async getFollowList () {
      const res = await this.$axios.get('/user_follows')
      const { statusCode, data } = res.data
      if (statusCode === 200) {
        this.list = data
      }
    },
    // 取消关注的说明
    async cancelFollow (id) {
      try {
        await this.$dialog.confirm({
          title: '温馨提示',
          message: '确认要取消关注吗'
        })
        const res = await this.$axios(`/user_unfollow/${id}`)
        const { statusCode } = res.data
        if (statusCode === 200) {
          this.$toast.success('取消关注成功')
          this.getFollowList()
        }
      } catch (e) {
        console.log(e)
      }
    },
    async follow (id) {
      const res = await this.$axios(`/user_follow/${id}`)
      const { statusCode } = res.data
      if (statusCode === 200) {
        this.$$toast.success('关注成功')
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.follow {
  .item {
    display: flex;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid #ccc;
    .left {
      width: 40px;
      height: 40px;
      border-radius: 50%;
      overflow: hidden;
      margin-right: 10px;
    }
    .center {
      flex: 1;
      line-height: 20px;
      .name {
        font-size: 16px;
        color: #000;
      }
      .time {
        font-size: 14px;
        color: #999;
      }
    }
    .right {
      height: 30px;
      line-height: 30px;
      padding: 0 15px;
      background-color: #e1e1e1;
      border-radius: 15px;
    }
  }
}
</style>
